public class Test2 {
    public static void print(int n) {
        if(n <= 9) {
            System.out.print(n+" ");
            return;
        }
        print(n/10);
        System.out.print(n%10+" ");
    }
    public static int add(int n) {
        int sum = 0;
        if(n == 1) {
           return 1;
        }
        return sum =n + add(n-1);
    }
    public static int sum(int a) {
        if(a<10) {
            return a;
        }
        return a%10+sum(a/10);
    }
    public static int fib1(int n) {//递归
        if(n == 1 || n == 2) {
            return 1;
        }
        return fib1(n-1)+fib1(n-2);
    }
    public static int fib2(int n) {//迭代
        if(n == 1 || n == 2) {
            return 1;
        }
        int f1 = 1;
        int f2 = 1;
        int f3 = 0;
        for (int i = 3; i <=n; i++) {
            f3 = f1 + f2;
            f1 = f2;
            f2 = f3;
        }
        return f3;
    }
    public static void main(String[] args) {
        //print(1234);
        //System.out.println(add(10));
        //System.out.println(sum(298));
        System.out.println(fib1(10));
        System.out.println(fib2(10));
    }
}
